0

I'm trying to get a date formatted between quotes on a select format() query:

select format('CREATE TABLE temporary_table AS
          SELECT id FROM table WHERE created >=%I ORDER BY 1 ASC LIMIT 1','2021-04-01');

I'm getting this:

CREATE TABLE temporary_table AS
              SELECT table FROM table WHERE created >="2021-04-01" ORDER BY 1 ASC LIMIT 1;

And I wanted to actually get the date between single quotes (as this won't work on an execute)

How can I achieve this?

1 Answer 1

1

For single-quoted values you need the specifier %L for format(). Like:

SELECT format('CREATE TABLE temporary_table AS
      SELECT id FROM table WHERE created >= %L ORDER BY 1 LIMIT 1','2021-04-01');

See:

Of course that only makes sense if you parameterize the input. You wouldn't bother to use format() for a constant date to begin with.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.