Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TABLE clause (for use with CREATE TABLE AS) #400

Closed
dharrigan opened this issue Mar 26, 2022 · 3 comments
Closed

Support TABLE clause (for use with CREATE TABLE AS) #400

dharrigan opened this issue Mar 26, 2022 · 3 comments
Assignees
Labels
documentation I need to write something up! enhancement

Comments

@dharrigan
Copy link

Hi,

From Slack (https://clojurians.slack.com/archives/C66EM8D5H/p1647902883353929). Original author is Nick Stares:

Hello, I'm trying to generate the following (postgres) SQL with honeysql:

CREATE TEMPORARY TABLE temp_table AS
TABLE display_impressions_reach_by_line_test
WITH NO DATA;

I've been playing around with argument orderings to create-table-as but no luck

(-> {:create-table-as [:temporary :table :temp_table :display_impressions_reach_by_line_test]}
    sql/format)
;; => ["CREATE TEMPORARY TABLE TEMP_TABLE TABLE display_impressions_reach_by_line_test AS"]

I can't figure out how I'm supposed to order the symbols in the argument vector.

@seancorfield
Copy link
Owner

TABLE display_impressions_reach_by_line_test is equivalent to SELECT * FROM display_impressions_reach_by_line_test and once that is understood, you can do this:

dev=> (sql/format {:create-table-as [:temporary :temp_table] 
                   :select :* 
                   :from :display_impressions_reach_by_line_test 
                   :with-data false})
["CREATE TEMPORARY TABLE temp_table AS SELECT * FROM display_impressions_reach_by_line_test WITH NO DATA"]

As a convenience, I'll add a :table clause.

@seancorfield seancorfield changed the title Support Temporary Table Creation (PostgreSQL) Support TABLE clause (for use with CREATE TABLE AS) Mar 26, 2022
@seancorfield seancorfield self-assigned this Mar 26, 2022
@seancorfield seancorfield added enhancement documentation I need to write something up! labels Mar 26, 2022
@seancorfield
Copy link
Owner

I'm tagging this with documentation to remind me to update the create table as docs with an example using the new table clause once it is implemented.

@seancorfield
Copy link
Owner

The following will work with that change:

dev=> (sql/format {:create-table-as [:temporary :temp_table] 
                   :table :display_impressions_reach_by_line_test 
                   :with-data false})
["CREATE TEMPORARY TABLE temp_table AS TABLE display_impressions_reach_by_line_test WITH NO DATA"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation I need to write something up! enhancement
Projects
None yet
Development

No branches or pull requests

2 participants